import diff from "./diff";

export default class Component {
  constructor(props) {
    this.props = props;
  }

  setState(state = {}) {
    // 返回一个新的对象
    this.state = Object.assign({}, this.state, state);
    // 获取最新的要渲染的vdom对象进行比对
    let vDom = this.render();

    // 获取旧的dom对象 ==> 获取旧的vdom对象
    let oldDom = this.getDom();

    // 获取渲染了页面的容器
    let container = oldDom.parentNode;

    // 实现对比，更新界面
    diff(vDom, container, oldDom);
  }

  setDom(dom) {
    this._dom = dom;
  }

  getDom() {
    return this._dom;
  }

  updateProps(props) {
    this.props = props;
  }
}
